package com.example.day2.AOP;

import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.example.day2.App;
import com.example.day2.busi.login.LoginActivity;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class LoginInterCepter {
    //定义规则
    @Pointcut("execution(@com.example.day2.entity.CheckLogin * *(..))")
    public void checkLogin(){}

    @Around("checkLogin()")
    public void aruondLogin(ProceedingJoinPoint point) throws Throwable {
        if (SPUtils.getInstance().getString("token").isEmpty()){
            ToastUtils.showLong("请先登录");
            Context context = App.getContext();
            Intent intent = new Intent();
            intent.setClass(context, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }else{
            point.proceed();
        }
    }
}
